<template>
    <div class="newsinfo-container">
        <h3 class="newsinfo-title">{{ newsInfo.title }}</h3>
        <p class="newsinfo-subtitle">
            <span>发表时间: {{ newsInfo.add_time | dateFormat }} </span>
            <span>点击数: {{ newsInfo.click }}</span>
        </p>
        <hr>
        <div class="newsinfo" v-html="newsInfo.content"></div>

        <!-- 将评论子组件添加到 页面中直接使用-->
        <comment :id="id"></comment>
    </div>
</template>

<script>

    import comment from '../subcomponent/Comment.vue'

    export default {
        name: "NewsInfo",
        data() {
            return {
                id: this.$route.params.id,
                newsInfo: {}
            }
        },
        created() {
            this.getNewsInfo()
        },
            methods: {
                getNewsInfo() {
                    this.$http.get('api/getnew/' + this.id).then(result => {
                        if(result.body.status === 0){
                            this.newsInfo = result.body.message[0]
                        }
                    })
                }
            },
            components:{   //定义并挂载子组件
                comment
            }
    }
</script>

<style scoped lang="less">
    .newsinfo-container{
        padding: 0 4px;

        .newsinfo-title{
            font-size: 16px;
            text-align: center;
            margin: 15px 0;
        }

        .newsinfo-subtitle{
            display: flex;
            justify-content: space-between;
        }
    }
</style>